package objects

import (
	"net/http"
	"strings"
	"io"
)

func get(w http.ResponseWriter, r *http.Request)  {
	path := r.URL.EscapedPath()
	///println(path)

	fileName := strings.Split(path, "/")[2]

	stream,err := getStream(fileName)
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	/**
	重构代码结构
	f,err := os.Open(config.GetString(STORGE_ROOT_KEY) + STORGE_OBJECTS + fileName)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(ERROR_OPEN_FILE))
		return
	}
	defer f.Close()
	*/
	io.Copy(w,stream)
}
